package bestHand;

import java.util.HashMap;
import java.util.Map;

public class Solution {
    public String bestHand(int[] ranks, char[] suits) {
        // 先检测同花
        if(checkFlush(suits))return "Flush";
        else if(checkThreeOfAKind(ranks))return "Three of a Kind";
        else if(checkPair(ranks))return "Pair";
        else return "High Card";
    }
    private boolean checkFlush(char[] suits) {
        return suits[0] == suits[1]&&
                suits[1] == suits[2]&&
                suits[2] == suits[3]&&
                suits[3] == suits[4];
    }
    private boolean checkThreeOfAKind(int[] ranks) {
        // 三张大小相同的牌
        Map<Integer,Integer>map = new HashMap<>();
        for (int i = 0; i < ranks.length; i++) {
            map.put(ranks[i],map.getOrDefault(ranks[i],0)+1);
            if(map.get(ranks[i]) == 3) {
                return true;
            }
        }
        return false;
    }
    private boolean checkPair(int[] ranks) {
        Map<Integer,Integer>map = new HashMap<>();
        for (int i = 0; i < ranks.length; i++) {
            map.put(ranks[i],map.getOrDefault(ranks[i],0)+1);
            if(map.get(ranks[i]) == 2) {
                return true;
            }
        }
        return false;
    }

}
